package com.qidian.mes.defect.controller;

import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.defect.service.ProcessService;
import com.qidianit.common.pojo.MESResult;
import com.qidianit.mes.pojo.Incoming;
import com.qidianit.mes.pojo.TestProcess;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * @Author 泽华
 * @Description
 * @Time 2024-10-23 23:44
 */
@RestController
@CrossOrigin
@RequestMapping("/process")
public class ProcessController {
    @Autowired
    private ProcessService processService;
    @GetMapping("/list")
    public MESResult list(TestProcess testProcess, @RequestParam(defaultValue = "1")int page, @RequestParam(defaultValue = "10") int limit){
        return processService.list(testProcess, page, limit);
    }

    @PostMapping("/save")
    public MESResult save(@RequestBody TestProcess testProcess){
        return processService.save(testProcess);
    }

    @PutMapping("/update")
    public MESResult update(@RequestBody TestProcess testProcess){
        return processService.update(testProcess);
    }

    @GetMapping("/get")
    public MESResult get(Long processId){
        return processService.selectById(processId);
    }


    @GetMapping("/export")
    public MESResult export(TestProcess testProcess, int page, int limit) {
        // 查询数据
        MESResult result = processService.list(testProcess, 1, 10);
        PageInfo<TestProcess> pageInfo = (PageInfo<TestProcess>) result.getData();
        List<TestProcess> testProcesses = pageInfo.getList();
        //  通过EasyExcel写数据
        int num = 200;
        try{
            EasyExcel.write("E:\\MES\\Excel\\testProcess-"+ page + limit + ".xlsx",
                            TestProcess.class)
                    .sheet("过程检验数据")
                    .doWrite(testProcesses);
        }catch (Exception e){
            num = 300;
        }
        return MESResult.success(num,"OK");
    }




}
